from bs4 import BeautifulSoup
import json as js
import numpy as np
import requests
import re


def getSongText(ID):
    url = 'http://music.163.com/api/song/media?id={}'.format(str(ID))
    info = requests.get(url)
    json = js.loads(info.content)
    lyric = json['lyric']
    patt = '\[.*\]'
    lyricRows = lyric.split('\n')
    for row in lyricRows:
        print(row.replace(re.findall(pattern=patt, string=row)[0], ''))
    # (lyricRows)


def getSongId(keyWord):
    keyWord = str(keyWord)
    searchUrl = r'https://music.163.com/#/search/m/?s={}&type=1'.format(keyWord)
    print(searchUrl)
    info = requests.get(url=searchUrl)
    soup = BeautifulSoup(info.text, 'html.parser')
    print(soup)
    searchList = soup.find_all(name='a', attrs={'href': True})
    print(searchList)


if __name__ == '__main__':
    print('请输入歌曲ID')
    id = str(input())
    getSongText(id)
